function inArr(key, arr) {
  for (var i in arr) {
    var val = arr[i];
    if (key.indexOf(val)) {
      return true;
    }
  }
  return false;
}

module.exports = function (req, res, next) {

  var url = req.originalUrl.toLowerCase();

  var arr = [
    '/login',
    '/fileUpload/img',
    '/fileUpload/doc',
    '/fileUpload/xls',
  ]

  if (inArr(url, arr)) {
    return next();
  }

  if (req.session.admin) {
    req.session.isAdmin = true;
  }
  if (!req.session.isAdmin) {
    return res.redirect('/login');
  }

  return next();

};
